#!/usr/bin/env python
# coding=utf-8


from typing import Any, Callable

from PySide6.QtCore import QObject
from PySide6.QtCore import Signal as _Signal
from PySide6.QtWidgets import QGraphicsOpacityEffect, QPushButton


class Signal(QObject):
    signal = _Signal()

    def emit_signal(self):
        self.signal.emit()


def reset_button_effect(btn: QPushButton, effect: QGraphicsOpacityEffect, *args, **kwargs):
    """SignalButton slot of btn reset with effect

    Args:
        btn (QPushButton): btn instance
        effect (QGraphicsOpacityEffect): QGraphicsOpacityEffect instance
    """

    btn.setText("")
    effect.setOpacity(0.7)


class SignalButton(Signal):
    """SignalButton is a wrapper around a single  Signal,
    which encapsulates the connection
    between the transmission of a single QPushButton signal and the slot function
    """

    def connect_slot(self, btn: QPushButton, fn: Callable[[QPushButton, Any], None] = None, *args, **kwargs):
        fn = fn if fn is not None else lambda *arg, **kwargs: btn.setText("")
        self.signal.connect(lambda: fn(btn, *args, **kwargs))
